package com.ctg.payroll2.action.payment;

import java.sql.SQLException;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.omg.CORBA.CurrentHolder;

import com.ctg.payroll2.bean.po.PayClass;
import com.ctg.payroll2.bean.po.SysUser;
import com.ctg.payroll2.bean.po.payment.PaySumClass;
import com.ctg.payroll2.service.payment.PaySumClassService;
import com.ctg.payroll2.util.Constants;
import com.opensymphony.xwork2.ActionSupport;

public class PaySumClassAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3704715359861100091L;

	private PaySumClassService paySumClassService;
	
	private List paySumClassList;

	private List notInPaySumClassList ;
	public void setPaySumClassService(PaySumClassService paySumClassService) {
		this.paySumClassService = paySumClassService;
	}

	public List getNotInPaySumClassList() {
		return notInPaySumClassList;
	}

	public void setNotInPaySumClassList(List notInPaySumClassList) {
		this.notInPaySumClassList = notInPaySumClassList;
	}

	public List getPaySumClassList() {
		return paySumClassList;
	}

	public void setPaySumClassList(List paySumClassList) {
		this.paySumClassList = paySumClassList;
	}

	public String insertPaySumClass() throws SQLException {
		String paySumClassId = ServletActionContext.getRequest().getParameter(
				"paySumClassId");
		String companyCode = ServletActionContext.getRequest().getParameter(
				"companyCode");
		String atClassId = ServletActionContext.getRequest().getParameter("atClassId");
		PaySumClass paySumClass = new PaySumClass();
		paySumClass.setCompanyCode(companyCode);
		paySumClass.setPayClassId(Integer.valueOf(paySumClassId));
		paySumClass.setAtClassId(Integer.valueOf(atClassId));
		paySumClassService.insertPaySumClass(paySumClass);

		return SUCCESS;
	}
	
	public String deletePaySumClass()throws SQLException {
		String paySumClassId = ServletActionContext.getRequest().getParameter(
		"paySumClassId");
		
		String atClassId = ServletActionContext.getRequest().getParameter("atClassId");
		PaySumClass paySumClass = new PaySumClass();
		paySumClass.setPayClassId(Integer.valueOf(paySumClassId));
		paySumClass.setAtClassId(Integer.valueOf(atClassId));
		paySumClassService.deletePaySumClass(paySumClass);
		return SUCCESS;
	}
	
	public String MegerPayClassById() throws SQLException {
		String paySumClassId = ServletActionContext.getRequest().getParameter(
				"paySumClassId");
		PaySumClass paySumClass = new PaySumClass();
		paySumClass.setPayClassId(Integer.valueOf(paySumClassId));
		paySumClassList = paySumClassService.getMegerPayClassById(paySumClass);
		return SUCCESS;
	}
	
	public String NotExistInPaySumClassById() throws SQLException{
		String paySumClassId = ServletActionContext.getRequest().getParameter(
		"paySumClassId");
		PayClass pc = new PayClass();
		SysUser currentUser = (SysUser)ServletActionContext.getRequest().getSession().getAttribute(Constants.CURRENT_USER);
		pc.setCompany_code(currentUser.getCompanyCode());
		pc.setPay_class_id(Long.valueOf(paySumClassId));
		notInPaySumClassList = paySumClassService.getNotExistInPaySumClassById(pc);
		return SUCCESS;
	}

}
